import request from '@/utils/request';

// 查询【请填写功能名称】列表
export function listIndicator(query) {
  return request({
    url: '/system/indicator/list',
    method: 'get',
    params: query
  })
}

// 查询【请填写功能名称】详细
export function getIndicator(id) {
  return request({
    url: '/system/indicator/' + id,
    method: 'get'
  })
}

// 新增【请填写功能名称】
export function addIndicator(data) {
  return request({
    url: '/system/indicator',
    method: 'post',
    data: data
  })
}

// 修改【请填写功能名称】
export function updateIndicator(data) {
  return request({
    url: '/system/indicator',
    method: 'put',
    data: data
  })
}

// 删除【请填写功能名称】
export function delIndicator(ids) {
  return request({
    url: '/system/indicator/' + ids,
    method: 'delete'
  })
}

export function getIndicatorsBySystemId(id) {
  return request({
    url: '/system/indicator/indicatorSys/'+id,
    method: 'get'
  })
}

export function getIndicatorsTree() {
  return request({
    url: '/system/indicator/indicatorsTree',
    method: 'get'
  })
}
export function search(name, startTime, endTime, dataSource, pageNum, pageSize, indicatorType) {
  const params = {
    name: name || null,
    startTime: startTime || null,
    endTime: endTime || null,
    dataSource: dataSource || null,
    pageNum: pageNum || null,
    pageSize: pageSize || null,
    indicatorType: indicatorType || null
  };

  // 过滤掉空值参数
  const filteredParams = Object.entries(params).reduce((acc, [key, value]) => {
    if (value !== null && value !== undefined && value !== '') acc[key] = value;
    return acc;
  }, {});

  return request({
    url: '/system/indicator/search',
    method: 'get',
    params: filteredParams
  });
}

/**
 * 查询:  指标id : need_data
 */
export function getIndicatorNeedData() {
  return request({
    url: `/system/indicator/needData`,
    method: 'get',
  });
}

export function getIndicatorName_DescMap(){
  return request({
    url: '/system/indicator/getIndicatorName_DescMap',
    method: 'get'
  })
}
